package cn.agiledata.security.db.action;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import cn.agiledata.security.db.form.EnctSelectForm;
import cn.agiledata.security.db.service.IEnctListService;
import cn.agiledata.security.db.util.TitleUtil;

import cn.agiledata.bank.common.util.Constant;
import cn.agiledata.bank.common.util.PageBean;
import cn.agiledata.bank.common.util.SelectUtil;
import cn.agiledata.bank.common.util.StringUtil;
import com.vnv.infrastructure.action.IPBBaseAction;
import com.vnv.infrastructure.logic.IPBAppFactory;


public class EnctAction extends IPBBaseAction implements Constant {
	



	/**
	 * 得到防止篡改列表
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	public ActionForward enctList(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) throws Exception {
		IEnctListService enctListService = (IEnctListService)IPBAppFactory.getObj("enctListService");
		EnctSelectForm theForm = (EnctSelectForm)form;
		if(StringUtil.isStrEmpty(theForm.getStartPage())) {
			theForm.setStartPage("1");
		}
		
		PageBean pb = null;
		String dbName = theForm.getDbName();
		String resultType = theForm.getResultType();
		if(!StringUtil.isStrEmpty(dbName)) {
			theForm.setPageSize(ENCTLISTPAGESIZE.toString());
			pb = enctListService.getEnctList(theForm);
		}
		
		List dbList = SelectUtil.renderDbSelectBean();
		List resultTypeList =  SelectUtil.renderResultTypeSelectBean();
		List titleList = TitleUtil.getDbTitle(dbName);
		
		request.setAttribute("enctList",pb);
		request.setAttribute("dbList", dbList);
		request.setAttribute("resultTypeList", resultTypeList);
		request.setAttribute("titleList", titleList);
		request.setAttribute("dbName", dbName);
		
		return mapping.findForward(SUCCESS);
	}
	
	/**
	 * 重新校验
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	public ActionForward reEnct(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) throws Exception {
		EnctSelectForm theForm = (EnctSelectForm)form;
		IEnctListService enctListService = (IEnctListService)IPBAppFactory.getObj("enctListService");
		enctListService.reEncr(theForm);
		return enctList(mapping,form,request,response);
	}
}
